package tour.spring.bc.assembler;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import tour.spring.bc.dto.RegionDto;
import tour.spring.bc.model.City;
import tour.spring.bc.model.Region;

@Component
public class RegionAssembler{

	@Autowired PlaceAssembler placeAssembler;
	
	public RegionDto convertToDto(Region region) {
		RegionDto regionDto = (RegionDto) placeAssembler.convertToDto(region);
		
		List<String> cityNames = new ArrayList<String>();
		List<City> cities = region.getCities();
		for (City city : cities) {
			cityNames.add(city.getName());
		}
		regionDto.setCitiesNames(cityNames);
		return regionDto;
	}
	
	public List<RegionDto> convertToDto(List<Region> regions) {
	
		ArrayList<RegionDto> list = new ArrayList<RegionDto>(); 
		for (Region region : regions) {
			list.add(convertToDto(region));
		}
		return list;
	}
}
